﻿using BarManager.Core.BusinessRules.Interfaces.Specification;
using BarManager.Core.DomainService;
using BarManager.Core.Entity;
using System.Collections.Generic;
using System.Linq;

namespace BarManager.Core.BusinessRules.Specification
{
    public class PromocionAddSpecificationProductos : BaseSpecification<Promocion>, IPromocionSpecification
    {
        private Promocion Promocion = null;

        public PromocionAddSpecificationProductos(IPromocionRepository repository)
            :base(repository)
        {
        }

        public override bool IsSatisfiedBy(Promocion entity)
        {
            var res = BaseRepository.Find(x=> x.PromocionDetalleList.Count > 0);

            foreach (var item in res)
            {
               
                    return false;
                
            }

            return (Promocion == null);
        }

        public override IEnumerable<string> GetErrorMessage()
        {
            if (Promocion != null) yield return string.Format("Ya existe la promocion {0} con los mismos productos", Promocion.Id);
            yield break;
        }
    }
}
